package com.zhoufy.service;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * Created with IntelliJ IDEA by ChouFy on 2020-04-14.
 *
 * @author zhoufy
 */
public class UserServiceHandle extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {


        //  判断是否符合约定   符合则调用本地方法返回
        //  msg: UserService#sayHello#args
        UserServiceImpl userService = new UserServiceImpl();
        if (msg instanceof RpcRequest || msg == null) {
            System.out.println("isok");
            ctx.writeAndFlush(userService.isOk((RpcRequest) msg));
            System.out.println(" ctx.writeAndFlush(s);");
        } else {
            System.out.println("sayhello");
            String s = userService.sayHello( msg.toString());
            ctx.writeAndFlush(s);
        }

    }
}
